package com.da.javatest.design.schema.singleton;

public class SingletonTest01 {
    //1. 构造器私有化, 外部能new
    private SingletonTest01() {}

    //2.本类内部创建对象实例
    private final static SingletonTest01 instance = new SingletonTest01();

    //3. 提供一个公有的静态方法，返回实例对象
    public static SingletonTest01 getInstance() {
        return instance;
    }

    public static void main(String[] args) {
        //测试
        SingletonTest01 instance = SingletonTest01.getInstance();
        SingletonTest01 instance2 = SingletonTest01.getInstance();
        System.out.println(instance == instance2); // true
        System.out.println("instance.hashCode=" + instance.hashCode());
        System.out.println("instance2.hashCode=" + instance2.hashCode());
    }
}
